#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define INFINITY 10000
#define MAX_SIZE 100
int MGraph[MAX_SIZE][MAX_SIZE];
typedef struct ENode *PtrToENode;
struct ENdode{
    int v1, v2;
    int weight;
};
int main()
{
    int N, M;
    int v1, v2, weight;
    scanf("%d %d", &N, &M);

    //init MGraph
    for (int i = 0; i < N;i++)
        for (int j = 0; j < N;j++)
            MGraph[i][j] = INFINITY;

    for (int i = 0; i < M; i++)
    {
        scanf("%d %d %d", &v1, &v2, &weight);
        //construct graph
        v1--;
        v2--;
        MGraph[v1][v2] = weight;
        MGraph[v2][v1] = weight;
    }
    //floyd matrix
    for (int k = 0; k < N;k++)
        for (int i = 0; i < N;i++)
            for (int j = 0; j < N;j++)
                if (MGraph[i][k] + MGraph[k][j] < MGraph[i][j])
                    MGraph[i][j] = MGraph[i][k] + MGraph[k][j];
                //i,k k,j -> i,j compare with i,j direct

    int Min_dis = 1000, Max_dis = 0;
    int record;
    //analysis
    for (int i = 0; i < N;i++)
    {
        for (int j = 0; j < N;j++)
        {
            if(i!=j && Max_dis< MGraph[i][j])
                Max_dis = MGraph[i][j];
        }
        if(Max_dis==INFINITY)
        {
            printf("0");
            break;
        }
        if(Min_dis > Max_dis)
        {
            Min_dis = Max_dis;
            record = i + 1;
        }
        Max_dis = 0;
    }
    if(Max_dis!=INFINITY)
        printf("%d %d", record, Min_dis);
    
    return 0;
}